// es5 从复杂的数据结构中提取数据：
/* es5:
let arr = ['hello', 'world'];
let firstName = arr[0]
console.log(firstName) */
// es6:
// let arr = ['hello', 'world'];
// let [firstName, lastNmae] = arr;
// console.log(firstName, lastNmae)

// 取第1,3,项：
// let arr = ['a', 'b', 'c', 'd']
// let [firstName, , thirdName] = arr
// console.log(firstName, thirdName)


// let arr = 'abcd' //支持所有可遍历的对象
// let [firstName, , thirdName] = arr
// console.log(firstName, thirdName)



// let [firstName, , thirdName] = new Set([1, 2, 3, 4]) //支持所有可遍历的对象,利用结构赋值
// console.log(firstName, thirdName)

// 给对象的属性重新命名
// let user = {
//     name: 's',
//     surname: 't'
// };
// [user.name, user.surname] = [1, 2];
// console.log(user);


// let arr = ['hello', 'world'];

// for (let i = 0, item; i < arr.length; i++) {
//     item = arr[i]
// }


// let user = {
//     name: 's',
//     surname: 't'
// }
// for (let [key, value] of Object.entries(user)) {
//     // 隐式赋值,显示索引
//     console.log(key, value)
// }

// let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
// let [firstName, curName, ...last] = arr;
// console.log(firstName, curName, last);

// 当数据量不够的时候undefined,...last是空数组 ,可以用=赋值默认值
let arr = []
let [firstName = 'hello', curName = 'world', ...last] = arr;
console.log(firstName, curName, last);